/**
 * encode params into querystring, like ?a=b&c=d etc.
 * @param {object} params
 * @param {boolean} useEncode
 * @returns {string}
 */
export default function stringifyQuery(params, useEncode) {
    if (!params) return '';

    const keys = Object.keys(params);
    if (keys.length <= 0) return '';
    
    return keys.map(key => {
            let value = params[key];
            if (value === undefined) return '';

            if (useEncode) {
                value = encodeURIComponent(value);
            }
            return key + '=' + value;
        })
        .filter(item => item)
        .join('&');
}